package com.dtborad.myblog.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dtborad.myblog.entity.Categories;
import com.dtborad.myblog.entity.Posts;
import com.dtborad.myblog.mapper.CategoriesMapper;
import com.dtborad.myblog.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoriesMapper, Categories> implements CategoryService {
    @Autowired
    private CategoriesMapper categoriesMapper;
    @Override
    public Page<Categories> getAllCategoryByPageSize(int pagenum, int pagesize, Integer categoryid, String categoryname) {
        LambdaQueryWrapper<Categories> wrapper = new LambdaQueryWrapper<>();
        // 根据 categoryid 过滤
        if (categoryid != null) {
            wrapper.eq(Categories::getCategoryid, categoryid);
        }

        // 根据 categoryname 过滤
        if (StrUtil.isNotBlank(categoryname)) {
            wrapper.like(Categories::getCategoryname, categoryname);
        }

        // 分页查询
        return categoriesMapper.selectPage(new Page<>(pagenum, pagesize), wrapper);
    }
}
